package com.longdaji.decoration.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.List;

import chihane.jdaddressselector.*;
import chihane.jdaddressselector.BottomDialog;
import chihane.jdaddressselector.model.City;
import chihane.jdaddressselector.model.County;
import chihane.jdaddressselector.model.Province;
import chihane.jdaddressselector.model.Street;
import mlxy.utils.Dev;

/**
 * Created by Kanade on 2018/3/17 0017.
 */

public class AddressPickerDialog extends chihane.jdaddressselector.BottomDialog {
    public AddressSelector selector;

    public AddressPickerDialog(Context context) {
        super(context, R.style.bottom_dialog);
        init(context);
    }

    public AddressPickerDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);

    }

    public AddressPickerDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);

    }

    private void init(Context context) {
        selector = new AddressSelector(context);
        setContentView(selector.getView());

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = Dev.dp2px(context, 256);
        window.setAttributes(params);

        window.setGravity(Gravity.BOTTOM);


    }

    public static chihane.jdaddressselector.BottomDialog show(Context context) {
        return show(context, null);
    }

    public static chihane.jdaddressselector.BottomDialog show(Context context, OnAddressSelectedListener listener) {
        chihane.jdaddressselector.BottomDialog dialog = new BottomDialog(context, R.style.bottom_dialog);
        dialog.setTitle("testtitle");
        dialog.setOnAddressSelectedListener(listener);
        dialog.show();

        return dialog;
    }

}